import { forwardRef, useRef } from "react";

//forwardRef函数，用于获取子组件中的DOM元素
const Son=forwardRef((props,ref)=>{
  return <input ref={ref}/>
})
function App() {
  const sonRef=useRef(null)
  return (
    <div className="App">
      <Son ref={sonRef}/>
      <button onClick={() => sonRef.current.focus()}>点击让子组件input框聚焦</button>
    </div>
  );
}

export default App;
